<!-- 候选人公示 -->
<template>
    <div class="app-container">
        <el-button @click="setPublicyTime" type="primary" plain style="margin-bottom: 18px;" v-if="resData==null">设置公示期</el-button>
        <el-table :data="tableData" v-loading="loading" stripe style="width: 100%">
            <el-table-column label="序号" type="index" align="center" />
            <el-table-column label="供应商名称" align="center" prop="hName" />
            <el-table-column label="最终报价(万元)" align="center" prop="finalOffer">
                <template slot-scope="scope">
                    {{ scope.row.finalOffer / 10000 }}
                </template>
            </el-table-column>
            <el-table-column label="最终得分" align="center" prop="finalScore" sortable />
            <el-table-column label="是否推荐" align="center" prop="recommend">
                <template slot-scope="scope">
                    <span>{{ scope.row.recommend == 0 ? '是' : '否' }}</span>
                </template>
            </el-table-column>
            <el-table-column label="排名" align="center" prop="ranking" sortable />
        </el-table>

        <el-dialog title="设置公示时间" :visible.sync="candidateOpen" width="60%">
            <el-row :gutter="15">
                <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="120px">
                    <el-col :span="12">
                        <el-form-item label="公示开始时间" prop="startTime">
                            <el-date-picker type="datetime" v-model="formData.startTime" format="yyyy-MM-dd HH:mm:ss"
                                value-format="yyyy-MM-dd HH:mm:ss" :style="{ width: '100%' }" placeholder="请选择日期选择"
                                clearable>
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公示结束时间" prop="endTime">
                            <el-date-picker type="datetime" v-model="formData.endTime" format="yyyy-MM-dd HH:mm:ss"
                                value-format="yyyy-MM-dd HH:mm:ss" :style="{ width: '100%' }" placeholder="请选择日期选择"
                                clearable>
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>
            <div slot="footer">
                <el-button @click="close">取消</el-button>
                <el-button type="primary" @click="handleConfirm">确定</el-button>
            </div>
        </el-dialog>
        
    </div>
</template>

<script>
import { getBidWinningCandidate, setStartTenderTime } from "@/api/system/purchase.js";

export default {
    data() {
        return {
            resData:{

            },//这个用来判断是否设置了公示期
            loading: true,
            iNumber: '',
            tableData: [
            ],
            // multipleSelection: [],
            candidateOpen: false,
            formData: {
                iNumber: '',
                startTime: '',
                endTime: ''
            },
            pStartTime:'',//评标开始时间
            pEndTime:'',//评标结束时间
            rules: {
                startTime: [
                    { required: true, message: '请选择公示开始时间', trigger: 'change' }
                ],
                endTime: [
                    { required: true, message: '请选择公示结束时间', trigger: 'change' }
                ]
            },
        }
    },
    methods: {
        getBidWinningCandidate() {
            getBidWinningCandidate(this.iNumber).then(res => {
                this.loading = false;
                this.resData= res.data.csTender;
                if (res.data.candidate != null) {
                    this.tableData = res.data.candidate;
                }
                if (res.data.csTender != null) {
                    this.formData = res.data.csTender;
                    this.$route.query.hEndTime = res.data.csTender.endTime
                    this.$route.query.hStartTime = res.data.csTender.startTime                    
                }
                if(res.data.csApplications!=null) {
                    this.startTime=res.data.csApplications.startTime;
                    this.endTime=res.data.csApplications.endTime;
                }
            })
        },
        setPublicyTime() {
            this.candidateOpen = true;
        },
        handleConfirm() {
            const startTime =new Date(this.startTime);//评标
            const endTime =new Date(this.endTime);
            const date=new Date();
            if(date<startTime||(date>startTime&&date<endTime)){
                this.$message({
                    type: 'warning',
                    message: '评标尚未结束!'
                });
                return false;
            }
            // 将时间字符串转换为日期对象  
            const start = new Date(this.formData.startTime);
            const end = new Date(this.formData.endTime);

            // 计算时间差（以天为单位）  
            const timeDifference = (end - start) / (1000 * 60 * 60 * 24); // 转换为天  
            // 检查时间差是否小于3天  

            // 可以使用,现在注释方便测试
            // if (timeDifference < 3) {
            //     this.$message({
            //         type: 'warning',
            //         message: '时间间隔不得小于3天，请重新填写!'
            //     });
            //     return false;
            // }
            setStartTenderTime(this.formData).then(res => {
                if (res.data > 0) {
                    this.$message({
                        type: 'success',
                        message: '设置成功!'
                    });
                    this.candidateOpen=false;
                    this.resData=this.formData;
                }
            })
        },
        close() {

        },
    },
    mounted() {
        this.iNumber = this.$route.query.iNumber;
        this.formData.iNumber = this.$route.query.iNumber;
        this.getBidWinningCandidate();
        console.log(this.$route.query,"这是测试路由中的参数");

    },

}
</script>
<style scoped></style>